package javax.core.common;

import java.util.List;

public class HttpApi<T> {

	private int code;
	private T data;
	private String msg;
	private List<String> errorsMsg;

	public HttpApi(T data) {
		this.code = 200;
		this.data = data;
	}

	public HttpApi(int code, T data, String msg, List<String> errorsMsg) {
		this.code = code;
		this.data = data;
		this.msg = msg;
		this.errorsMsg = errorsMsg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public static <T> HttpApi<T> ok(T data) {
		return new HttpApi<T>(200, data, "", null);
	}

	public static <T> HttpApi<T> err(int code, String msg) {
		return new HttpApi<T>(code, null, msg, null);
	}

	public static <T> HttpApi<T> err(int code, String msg, List<String> errorsMsg) {
		return new HttpApi<>(code, null, msg, errorsMsg);
	}

	public List<String> getErrorsMsg() {
		return errorsMsg;
	}

	public void setErrorsMsg(List<String> errorsMsg) {
		this.errorsMsg = errorsMsg;
	}
}
